<?php
/**
 * Api接口校验
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/1/23
 * Time: 17:11

 */
namespace App\Services\Warehouse;
class ValidateUserService extends PublicService {


  public function __construct()
  {
      parent::__construct('');
  }


    /**登陆验证
     * LoginResultType 登陆状态
     * 如下：
     *  //激活
    Activation = -7,
    //云通行证未绑定Cloud账号
    EntryCloudUnBind = -6,
    //需要表单处理
    DealWithForm = -5,
    //登录警告
    Wanning = -4,
    //密码验证不通过（强制的）
    PWInvalid_Required = -3,
    //密码验证不通过（可选的）
    PWInvalid_Optional = -2,
    //登录失败
    Failure = -1,
    //用户或密码错误
    PWError = 0,
    //登录成功
    Success = 1
     */
  public function login(){
    $url=$this->HttpClientService->config['WebUrl'].$this->HttpService->config['ValidateUser'];
    $data=[
        'acctID'=>$this->HttpClientService->config['k3uid'],
        'username'=>$this->HttpClientService->config['username'],
        'password'=>$this->HttpClientService->config['pass'],
        'lcid'=>$this->HttpClientService->config['lcid']
    ];
    $response=$this->HttpClientService->Http->request('POST',$url,[
          'form_params'=>$data,
      ],['cookies'=>$this->HttpClientService->CookieJar]);
    $res=json_decode((string) $response->getBody(), true);
    dd($res);
    if($res['LoginResultType']==1){
        $ReturnData=[
            'LoginResultType'=>$res['LoginResultType'],
            'UserId'=>$res['Context']['UserId'],
            'UserName'=>$res['Context']['UserName'],
            'CustomName'=>$res['Context']['CustomName'],
            'DisplayVersion'=>$res['Context']['DisplayVersion'],
            'DataCenterName'=>$res['Context']['DataCenterName'],
            'UserToken'=>$res['Context']['UserToken'],
            'Message'=>$res['Message']
        ];
        return $ReturnData;
    }else{
        $data=[
            'LoginResultType'=>$res['LoginResultType'],
            'Message'=>$res['Message']
        ];
        return $data;
    }
  }
}